package com.ys.controller.web.business;

import com.ys.entity.business.TpAmazonShop;
import com.ys.entity.business.TpShopStopPhaseRecord;
import com.ys.entity.business.TpShopStopPhaseSet;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/web/business/tpShopStopPhaseRecord")
public class WebTpShopStopPhaseRecordController {


	/**
	 * 完成页面
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model,long id,int phaseNum,String vGsBm){
		//查询店铺信息
		List<TpAmazonShop> shopList = new TpAmazonShop()
				.where("A.AuthorizeState = '已授权'")
				.where("A.Vgsbm = '" + vGsBm + "'")
				.queryList();
		ToEditDto dto = new ToEditDto(shopList,id,phaseNum);
		model.addAttribute("dto", dto);
		return "business/tpShopStopPhaseRecord/toEdit";
	}
	@Data
	@AllArgsConstructor
	private static class ToEditDto{
		private List<TpAmazonShop> shopList;
		private long id;
		private int phaseNum;
	}


	/**
	 * 输入工作内容页面
	 */
	@GetMapping("/toContent")
	public String toContent(Model model,long id){
		//获取记录表信息
		TpShopStopPhaseRecord recordInfo = new TpShopStopPhaseRecord()
				.where("A.Id = " + id)
				.queryFirst();
		//是否已经完成
		int hasFinish = ((recordInfo.getWorkTime()!=null && !recordInfo.getWorkTime().equals(""))?1:0);
		String workContent = recordInfo.getWorkContent();
		ToContentDto dto = new ToContentDto(id,hasFinish,workContent);
		model.addAttribute("dto", dto);
		return "business/tpShopStopPhaseRecord/toContent";
	}
	@Data
	@AllArgsConstructor
	private static class ToContentDto{
		private long id;
		private int hasFinish;
		private String workContent;
	}


	/**
	 * 选择店铺页面
	 */
	@RequiresPermissions("tpShopStopPhaseRecord:chooseShop")
	@GetMapping("/toChooseShop")
	public String toChooseShop(Model model,long id,int phaseNum,String vGsBm){

		//查询店铺信息
		List<TpAmazonShop> shopList = new TpAmazonShop()
				.where("A.AuthorizeState = '已授权'")
				.where("A.Vgsbm = '" + vGsBm + "'")
				.queryList();
		ToShopDto dto = new ToShopDto(shopList,id,phaseNum);
		model.addAttribute("dto", dto);
		//return "business/tpShopStopPhaseRecord/toChooseShop";
		return "business/tpShopStopPhaseRecord/chooseShop";
	}
	@Data
	@AllArgsConstructor
	private static class ToShopDto{
		private List<TpAmazonShop> shopList;
		private long id;
		private int phaseNum;
	}


	/**
	 * 详情页面
	 */
	@GetMapping("/toDetail")
	public String toDetail(Model model,long operateCompanyId){
		/*
		//获取列表数据
		List<YsCol> listField = new YsCol()
				.setMenuId(MENU_ID)
				.where("A.Code != 'ope'")
				.setOrderby("A.SortNo asc")
				.queryList();
		List<Map<String,Object>> colList = new ArrayList<>();
		for(int i=0;i<listField.size();i++){
			Map<String,Object> msg = new HashMap<>();
			msg.put("title",listField.get(i).getName());
			msg.put("field",listField.get(i).getCode());
			msg.put("align","center");
			//title: listField[i].name, field:listField[i].code, align:"center"
			colList.add(msg);
		}
		JSONArray colArray = JSONArray.parseArray(JSON.toJSONString(colList));
		 */
		ToDetailDto dto = new ToDetailDto(operateCompanyId);

		model.addAttribute("dto", dto);
		return "business/tpShopStopPhaseRecord/toDetail";
	}
	@Data
	@AllArgsConstructor
	private static class ToDetailDto{
		//private JSONArray colArray;
		private long operateCompanyId;
	}
}



